import http from "@/axios/index.js";
import {handleSuccess,handleError} from "@/api/index.js";

export const MenuApi = {
    // 创建菜单
    create(data) {
        return http.post('/api/menu/create', data)
            .then(res => handleSuccess(res, '创建成功'))
            .catch(err => handleError(err, '创建失败', '创建失败'))
    },

    // 更新菜单
    update(data) {
        return http.put('/api/menu/update', data)
            .then(res => handleSuccess(res, '更新成功'))
            .catch(err => handleError(err, '更新失败', '更新失败'))
    },

    // 删除菜单
    delete(id) {
        return http.delete(`/api/menu/delete/${id}`)
            .then(res => handleSuccess(res, '删除成功'))
            .catch(err => handleError(err, '删除失败', '删除失败'))
    },

    // 分页查询菜单列表
    list(params) {
        return http.get('/api/menu/list', { params })
            .then(res => handleSuccess(res, '查询成功'))
            .catch(err => handleError(err, '查询失败', '查询失败'))
    },

    // 获取菜单详情
    detail(id) {
        return http.get(`/api/menu/detail/${id}`)
            .then(res => handleSuccess(res, '获取菜单详情成功'))
            .catch(err => handleError(err, '获取菜单详情失败', '获取菜单详情失败'))
    },

    // 获取菜单树
    tree() {
        return http.get('/api/menu/tree')
            .then(res => handleSuccess(res, '获取菜单树成功'))
            .catch(err => handleError(err, '获取菜单树失败', '获取菜单树失败'))
    }
}